<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>忘记密码 - 个人博客系统</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../static/layui/css/layui.css" media="all" th:href="@{/layui/css/layui.css}">
    <link rel="stylesheet" href="../../static/layui/css/admin.css" media="all" th:href="@{/layui/css/admin.css}">
    <link rel="stylesheet" href="../../static/layui/css/login.css" media="all" th:href="@{/layui/css/login.css}">
</head>

<div class="layadmin-user-login layadmin-user-display-show" id="LAY-user-login" >
    <div class="layadmin-user-login layadmin-user-display-show" id="LAY-user-forget">
        <div class="layadmin-user-login-main">
            <div class="layadmin-user-login-box layadmin-user-login-header">
                <h2>找回密码</h2>
                <h5>第一步：输入邮箱</h5>
                <font style="color: red"></font>
            </div>
            <div class="layadmin-user-login-box layadmin-user-login-body layui-form">
                <div class="layui-form-item">
                    <label class="layadmin-user-login-icon layui-icon layui-icon-cellphone"
                           for="LAY-user-login-email"></label>
                    <input type="text" name="email" id="LAY-user-login-email"
                           placeholder="请输入注册时的邮箱" class="layui-input">
                    <div id="email_check"></div>
                </div>

                <!--<div class="layui-form-item">
                    <label class="layadmin-user-login-icon layui-icon layui-icon-password"
                           for="LAY-user-login-password"></label>
                    <input type="password" name="password" id="LAY-user-login-password" lay-verify="pass"
                           placeholder="请输入新密码" class="layui-input">
                    <div id="password_check"></div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-row">
                        <div class="layui-col-xs7">
                            <label class="layadmin-user-login-icon layui-icon layui-icon-vercode"
                                   for="LAY-user-login-vercode"></label>
                            <input type="text" name="vercode" id="LAY-user-login-vercode" lay-verify="required"
                                   placeholder="验证码" class="layui-input">
                        </div>
                        <div class="layui-col-xs5">
                            <div style="margin-left: 10px;">
                                <button type="button" class="layui-btn layui-btn-primary layui-btn-fluid"
                                        id="LAY-user-getsmscode">获取验证码
                                </button>
                            </div>
                        </div>
                        <div id="code_check"></div>
                    </div>
                </div>-->
                <div class="layui-form-item">
                    <button id="for_submit" class="layui-btn layui-btn-fluid" lay-submit
                            lay-filter="LAY-user-reg-submit">发送验证码
                    </button>
                </div>
                <button class="layui-btn layui-btn-fluid" onclick="history.go(-1)">返回</button>
            </div>

        </div>


    </div>


</div>

<script src="../../static/layui/layui.js" th:src="@{/layui/layui.js}"></script>
<script src="../../static/js/jquery-1.8.3.min.js" th:src="@{/js/jquery-1.8.3.min.js}"></script>
<script type="text/javascript" th:inline="javascript">


    function checkEmail() {
        //1.定义正则表达式
        var pattern = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
        //2.获取员工姓名
        var email = $("#LAY-user-login-email").val();
        //3.判断 给出提示信息
        var flag = pattern.test(email);
        if (!flag) {
            //不合法
            $("#email_check").html('<i style="color: red" class="layui-icon layui-icon-close"></i><span\n' +
                '                            style="color: red;">邮箱格式不正确</span>')
        } else {
            //合法
            $("#email_check").html('<i style="color: green" class="layui-icon layui-icon-ok"></i><span\n' +
                '                            style="color: green;">邮箱格式正确</span>');
        }

        return flag;
    }


    $("#LAY-user-login-email").blur(checkEmail);

    layui.use(['form', 'jquery','layer'], function () {
        var form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成功
        var $ = layui.jquery;
        var layer = layui.layer;

        form.on('submit(LAY-user-reg-submit)', function (data) {
            var c1 = checkEmail();
            if (c1) {
                $("#for_submit").html('<i class="layui-icon layui-icon-loading layui-anim layui-anim-rotate layui-anim-loop"></i>');
                $.post(/*[[@{/user/forget/sendCode}]]*/"/user/forget/sendCode", data.field, function (res) {
                    if (res.flag) {
                        $("#for_submit").html("发送验证码");
                        layer.msg(res.msg);
                        var email = res.email;
                        var url = /*[[@{'/user/forget/toUpdate?email='}]]*/"";
                        location.href = url + email;
                    } else {
                        layer.msg(res.msg);
                    }

                });
            }
        });
    });
</script>
<script>


    layui.use('form', function () {
        var form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成功

        //……

        //但是，如果你的HTML是动态生成的，自动渲染就会失效
        //因此你需要在相应的地方，执行下述方法来手动渲染，跟这类似的还有 element.init();
        form.render();//在最后添加这句代码
    });


</script>
</body>
</html>